package cat.sun.dialogs;

import cat.sun.R;
import cat.sun.activities.Game;
import cat.sun.activities.Game.ResumeReason;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class QuitDialog extends DialogFragment
{
	
	public static QuitDialog newInstance()
	{
		QuitDialog dialog = new QuitDialog();
		return dialog;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{		
		super.onCreate(savedInstanceState);
		setStyle(DialogFragment.STYLE_NO_FRAME, 0);	
		setCancelable(false);		
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) 
	{
		View view = inflater.inflate(R.layout.dialog_quit, container,false);						
		
		final ImageView close = (ImageView) view.findViewById(R.id.dialog_quit_close);
		
		close.setOnClickListener(new View.OnClickListener() 
		{
			
			@Override
			public void onClick(View v) 
			{
				((Game)getActivity()).Resume(ResumeReason.program);
				dismiss();				
			}			
		});
		
		getDialog().setOnKeyListener(new OnKeyListener() 
    	{			
			@Override
			public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) 
			{
				if (keyCode == KeyEvent.KEYCODE_BACK) 
				{
					((Game)getActivity()).Resume(ResumeReason.program);
					dismiss();
                }
				return true;
			}
		});
					
		ImageView ok = (ImageView) view.findViewById(R.id.dialog_quit_ok);
		ImageView cancel = (ImageView) view.findViewById(R.id.dialog_quit_cancel);
		
		TextView txtCancel = (TextView) view.findViewById(R.id.dialog_quit_text_cancel);
		TextView txtExit = (TextView) view.findViewById(R.id.dialog_quit_text_exit);
		TextView txtTitle = (TextView) view.findViewById(R.id.dialog_quit_title);
		
		txtCancel.setTypeface(Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Black.ttf"));
		txtExit.setTypeface(Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Black.ttf"));
		txtTitle.setTypeface(Typeface.createFromAsset(getActivity().getAssets(), "fonts/Roboto-Black.ttf"));
		
		
		ok.setOnClickListener(new View.OnClickListener() 
		{		
			@Override
			public void onClick(View v) 
			{
				((Game)getActivity()).finish();
				dismiss();
			}
		});
		
		cancel.setOnClickListener(new View.OnClickListener() 
		{			
			@Override
			public void onClick(View v) 
			{
				((Game)getActivity()).Resume(ResumeReason.program);
				dismiss();			
			}
		});
		
		return view;
	}
	
	

}
